package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class MyFrame2 extends JFrame implements ActionListener{
	private static final long serialVersionUID = 1L;
	private JTextField nameTf;
	private JPasswordField pwdPf;
	private JButton loginBtn;
	private JButton cancelBtn;
	private JLabel nameLa;
	private JLabel pwdLa;
	
	public MyFrame2(){
		this.setSize(400, 300);
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setTitle("QQ cheap copy");
		
		init();
		addEvent();
		this.setVisible(true);
	}
	
	private void init(){
		this.setLayout(null);
		nameTf = new JTextField();
		pwdPf = new JPasswordField();
		loginBtn = new JButton("Log In");
		cancelBtn = new JButton("Cancel");
		nameLa = new JLabel("User");
		pwdLa = new JLabel("Password");
		
		nameTf.setBounds(100, 40, 260, 30);
		pwdPf.setBounds(100, 90, 260, 30);
		loginBtn.setBounds(90, 200, 90, 30);
		cancelBtn.setBounds(210, 200, 90, 30);
		nameLa.setBounds(30, 40, 60, 30);
		pwdLa.setBounds(30, 90, 60, 30);
		
		
		this.add(nameTf);
		this.add(pwdPf);
		this.add(loginBtn);
		this.add(cancelBtn);
		this.add(nameLa);
		this.add(pwdLa);
		
	}
	private void addEvent(){
		loginBtn.addActionListener(this);
		
//		loginBtn.addFocusListener(new FocusListener() {
//			
//			public void focusLost(FocusEvent e) {
//				// TODO Auto-generated method stub
//				System.out.println("focus lost");
//			}
//			
//			public void focusGained(FocusEvent e) {
//				// TODO Auto-generated method stub
//				System.out.println("focus");
//			}
//		});
		
		cancelBtn.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				nameTf.setText(null);
				pwdPf.setText(null);
			}
		});
	}
	
	
	public static void main(String[] args) {
		new MyFrame2();
	}

	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		String nameString = nameTf.getText();
		String pwdString = new String(pwdPf.getPassword());
	
		System.out.println("login...."+nameString+".."+pwdString);
	}

}
